package edu.cs.usask.ca.silver.plugin.rcp.dialogs.select;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;

import edu.cs.usask.ca.silver.plugin.rcp.views.projectviewer.ProjectView;
import edu.cs.usask.ca.silver.plugin.rcp.views.projectviewer.ProjectViewI;

public class SelectFromProjectTreeDialog extends Dialog {

	private final ProjectViewI projectView;

	public SelectFromProjectTreeDialog(Shell parentShell,
			ProjectViewI selectedProjectView) {
		super(parentShell);
		setShellStyle(getShellStyle());
		this.projectView = selectedProjectView;
	}

	@Override
	public void create() {
		super.create();
	}

	@Override
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText("Select From ProjectTree");
	}

	@Override
	protected Control createDialogArea(Composite parent) {
		final Composite composite = new Composite(parent, SWT.RESIZE);

		composite.setLayout(new GridLayout());

		final TreeViewer treeviewer = new TreeViewer(composite, SWT.BORDER);

		GridData gd = new GridData();
		gd.horizontalSpan = 2;
		gd.horizontalIndent = 2;
		gd.horizontalAlignment = GridData.FILL;
		gd.verticalAlignment = GridData.FILL;
		gd.grabExcessHorizontalSpace = true;
		gd.grabExcessVerticalSpace = true;
		gd.minimumHeight = 300;
		gd.minimumWidth = 250;
		treeviewer.getControl().setLayoutData(gd);

		treeviewer.setContentProvider(projectView.getTreeViewer()
				.getContentProvider());
		treeviewer.setLabelProvider(projectView.getTreeViewer()
				.getLabelProvider());
		treeviewer.setInput(projectView.getSilverTreeRoot());
		return composite;

	}
}
